package com.duobeiyun.gmstest.file;

import android.content.Context;
import android.os.Environment;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 文件管理类
 */
public class FIleManager {
    private static FileOutputStream fos;
    private static boolean isWrite = true;

    public static void create(Context context) {
        if (!isWrite) {
            return;
        }
        File file = new File(context.getExternalCacheDir() + File.separator + "dby_gms_test.txt");
        try {
            fos = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    public static void close() {
        if (!isWrite) {
            return;
        }
        try {
            if (fos != null)
                fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        fos = null;
    }

    public static void write(byte[] data) {
        if (!isWrite) {
            return;
        }
        try {
            if (fos != null) {
                fos.write(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void writeString(String data) {
        if (!isWrite) {
            return;
        }
        try {
            if (fos != null) {
                fos.write(data.getBytes());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
